#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    void solve(vector<vector<char>>& board) {
        int m = board.size(), n = board[0].size();

        int dx[4] = { 0,0,1,-1 };
        int dy[4] = { 1,-1,0,0 };
        function<void(int, int)>
            dfs = [&](int r, int c)
            {
                board[r][c] = '.';
                for (int i = 0; i < 4; i++)
                {
                    int x = r + dx[i];
                    int y = c + dy[i];
                    if (x >= 0 && y >= 0 && x < m && y < n && board[x][y] == 'O')
                        dfs(x, y);
                }
            };

        for (int i = 0; i < m; i++)
        {
            if (board[i][0] == 'O')
                dfs(i, 0);
            if (board[i][n - 1] == 'O')
                dfs(i, n - 1);
        }
        for (int j = 0; j < n; j++)
        {
            if (board[0][j] == 'O')
                dfs(0, j);
            if (board[m - 1][j] == 'O')
                dfs(m - 1, j);
        }
        for (int i = 0; i < m; i++)
            for (int j = 0; j < n; j++)
                if (board[i][j] == '.') board[i][j] = 'O';
                else if (board[i][j] == 'O') board[i][j] = 'X';
    }
};